package com.len.pdms.web;

import com.alibaba.fastjson.JSON;
import com.len.base.BaseController;
import com.len.pdms.model.vo.TenantVo;
import com.len.pdms.service.TenantService;
import com.len.util.UploadUtil;
import io.swagger.annotations.Api;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping(value = "/pdms/tenant")
@Api(value = "租户管理")
public class TenantController extends BaseController {

    @Reference
    private TenantService tenantService;

    @Autowired
    private UploadUtil uploadUtil;

    @GetMapping(value = "/register")
    public String register(Model model){
        return "/tenant-register";
    }
    @PostMapping(value = "/addTenant")
    public String addTenant(TenantVo tenantVo, Model model) {
        System.err.println(JSON.toJSONString(tenantVo));
        tenantService.addTenant(tenantVo);
        model.addAttribute("username",tenantVo.getUsername());
        return "/tenant-register-success";
    }





    @PostMapping(value = "/update")
    @ResponseBody
    public String update(@RequestParam("file") MultipartFile multipartFile){
        String upload = uploadUtil.upload(multipartFile);
        System.out.println("图片名称>>>>"+upload);
        return "<img src='/images/"+upload+"' />";
    }
    @GetMapping(value = "/updatefile")
    public String update(){
        return "update";
    }

}
